﻿<%@ 
page language="java" 
import="java.util.*" 
import="com.csd.pojo.Student" 
import="com.csd.pojo.Team" 

import="com.csd.pojo.ProjectType"
import="com.csd.vo.UserVO"
import="com.csd.helper.IConstant"
pageEncoding="UTF-8"
%>
<%@ taglib prefix="s" uri="/struts-tags"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";

HttpSession s = request.getSession();
UserVO uvo =  (UserVO)s.getAttribute(IConstant.userVO);
boolean hasProjectOrNot = (Boolean)s.getAttribute("hasProjectOrNot");


Integer max = (Integer)s.getAttribute("projectMaxMemberCount");//从TeamShowAction层获取项目类型人数上限

if(uvo==null || !uvo.getType().equals(IConstant.teamRole))
{
	response.sendRedirect(path);
}

List<Student> stuList = (List<Student>)request.getAttribute("members");

if(stuList==null)
{
	response.sendRedirect(path+"/common/error.jsp?info=stuList null");
}

String projectTypeIDString = (String)s.getAttribute("projectTypeID");
String projectTypeID = (String)request.getParameter("projectTypeID");
if((projectTypeIDString != null) && (projectTypeID == null))
{
	projectTypeID = projectTypeIDString;
}
Team team = (Team)request.getAttribute("team") ;
Integer teamID = team.getId();
Integer leaderId = -1;
if(team != null)
{
	Student leader = team.getLeader();
	if(leader != null)
	{
		leaderId = leader.getId();
	}
}

String projstat = (String)request.getAttribute("projectState");

%>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>我的团队</title>
<link href="<%=path %>/student/css/student_right.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="<%=path %>/student/js/check.js"></script>
<script type="text/javascript">
var flag = 1;
function cls(){
var area=document.getElementsByName('name')
if( area[0].value== '字数不超过20'){area[0].value =""; area[0].style.color = '#000000'; }
}
</script>
<script type="text/javascript">

function hint(){
var area=document.getElementsByName('name')
if(area[0].value == ""){area[0].style.color = '#ACA899'; area[0].value = '字数不超过20'; }
}
</script>
<script type="text/javascript">
function cls1(){
var area=document.getElementsByName('introduction')
if( area[0].value== '字数不超过200'){area[0].value =""; area[0].style.color = '#000000'; }
}
</script>
<script type="text/javascript">

function hint1(){
var area=document.getElementsByName('introduction')
if(area[0].value == ""){area[0].style.color = '#ACA899'; area[0].value = '字数不超过200'; }
}
</script>
</head>

<body onload="hint();hint1();">
    <div class="main">
        <h1>我的团队</h1>
        
        <hr />
        <form method="post" action="<%=path %>/teamSave.action" onsubmit="return checkForm(this);">
		<input type="hidden" name="projectTypeID" value="<%=projectTypeID %>"/>
        <table align="center">
            <tr>
                <td class="form_strong" width="100px">团队名称：</td>
                <td><input maxLength="20" id="name" name="name" type="text" value="<s:property value="team.name"/>" onblur="checkNotNull(this);hint();" onfocus="cls();" onkeydown="checkInputLength(this, 0, 20);" onkeyup="checkNotNull(this);"/></td>
            </tr>
            <tr>
                <td class="form_strong">团队简介：</td>
                <td>
                    <textarea id="introduction" name="introduction"  cols="50" rows="10" onblur="checkNotNull(this);hint1();"onfocus="cls1();" onkeydown="checkTextAreaLength(this, 0, 200);" onkeyup="checkNotNull(this);"><s:property value="team.introduction" /></textarea>
                </td>
            </tr>
            <tr>
                <td class="form_strong">团队成员:</td>
                <td>
                	
                    <table width="100%"  style="table-layout:fixed;word-wrap:break-word;">
                        <thead>
                            <td class="table_head" width="50px">队长</td>
                            <td class="table_head" width="100px">学号</td>
                            <td class="table_head" width="100px">姓名</td>
                            <td class="table_head" width="100px">专业</td>
                            <td class="table_head" width="100px">年级</td>
                            <td class="table_head" width="100px">邮箱</td>
                            <td class="table_head" width="50px">操作</td>
                        </thead>
                        <%
                        	for(Student stu : stuList)
                        	{
                        %>
                        <tr>
                            <td><input type="radio" name="leaderID" value="<%=stu.getId() %>" id="leaderID"  <%if(leaderId.equals(stu.getId())){ %>checked="checked" <%} %>/></td>
                            <td><%=stu.getSno() %></td>
                            <td><%=stu.getName() %></td>
                            <td><%=stu.getMajor() %></td>
                            <td><%=stu.getGrade() %></td>
                            <td><%=stu.getEmail() %></td>
                            <td>
                            <%if(!leaderId.equals(stu.getId())){ %>	<a href="<%=path %>/memberDelete.action?memberID=<%=stu.getId() %>&projectTypeID=<%=projectTypeID %>">删除</a>
                            <%} %>
                            </td>
                        </tr>
                        <%} %>
                        <tr>
                            <td colspan="5">
                            <% if(!hasProjectOrNot) { %>
                            	<span>申请完项目，才可以添加项目成员</span>
                            <% } else if(stuList.size() == max){%>
                                <span>你添加的人数已达到上限,不能再添加新成员</span>
                            <% } else if(stuList.size() > max) { %>
                                <span>人数已超过上限，请在“我的团队”中删除成员后再试</span>
                                <script type="text/javascript">
                                	flag = 0;
                                </script>
                            <%}else { %><a href="<%=path %>/student/addMember.jsp?projectTypeID=<%=projectTypeID %>&teamID=<%=teamID %>">添加新的组员</a>
                            <% } %>
                            </td>
                        </tr>
                  </table>
                  
              </td>
            </tr>
            <tr>
                <td colspan="2" align="center">
                	<%if(projectTypeID == null || projectTypeID.equals("null") || projectTypeID.length() == 0) { %>
                   		<input type="submit" value=" 提交 " />
                    <%} else {%>
                    	<input type="submit" name="limit" id="limit" value="下一步" />
                    	<script type="text/javascript">
                    		if (!flag)
                    			document.getElementById('limit').disabled = true;
                    	</script>
                    <%} %>
                </td>
            </tr>
        </table>
	</form>
    </div>
</body>
</html>